var express = require("express");
var path = require("path");
var http = require("http");


var dbmodel = require("./database/dbmodel.js");

var dbutil = require("./database/dbutil.js");
var game = require("./routes/game");
var app = module.exports = express();


app.use(express.json());
app.use(express.urlencoded());
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
//app.use(express.cookieParser());
//app.use(express.session({secret: "Tireheb1996"}));
//Authenticator

// setup routes with appropriate authentication
//var auth = express.basicAuth('admin', '9192631770');
/*app.use(express.basicAuth(function (user, pass, callback) {
    var result = (user === "testuser" && pass === "testpass");
    callback(null error, result);
}));
*/



app.post("/login", game.createUser);
app.post("/online", game.lookonline);
app.post("/findAll", game.userList);
app.post("/remove", game.remove);
app.post("/change", game.change);




app.get("/", function (req, res) {
    res.render("test1");
});



/*app.get("dune", function(req, res){
    dbutil.lookup.render();
});
*/
//app.listen(8882);

http.createServer(app).listen(8888, function () {
    //dbutil.runonce();  artifact for recreating admin user in case i delete my database again :-(

 });
